<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="renderer" content="webkit|ie-comp|ie-stand">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <title>供应商管理列表</title>
  <script src="../../../static/kaige/js/szload.js"></script>
</head>

<body>

  <div class="kaige-body layui-form ">
    <table class="layui-table" id="pageTable" lay-filter="pageTable" lay-size="sm"></table>
    <input type="hidden" name="keywordsCache" value="{}" />
  </div>
  <script>
    load_init_js([
      szoapcpath + '/static/kaige/js/date.js',
      szoapcpath + '/static/kaige/js/search.js',
      szoapcpath + '/static/kaige/js/xm-select.js',
      szoapcpath + '/static/lib/Convert_Pinyin.js',
    ], function () {
      layui.config({
        base: szoapcpath + '/static/kaige/layuiextend/'
      }).use(['element', 'form', 'layedit', 'laydate', 'table', 'kaige', 'treeTable', 'laytpl', 'tableSelect', 'glfiles', 'transfer'], function () {
        var form = layui.form,
          table = layui.table,
          laydate = layui.laydate,
          kaige = layui.kaige,
          element = layui.element,
          treeTable = layui.treeTable,
          laytpl = layui.laytpl,
          tableSelect = layui.tableSelect,
          glfiles = layui.glfiles,
          transfer = layui.transfer;
        form.render();
        window.pagedict = parent.window.kaige_page.dict || {};
        //系统默认图片
        window.default_image = szoapcpath + "/static/img/default.png";
        //查看图片
        window.viewImage = function (imgUrl) { kaige.viewimage({ maxwidth: 600, maxheight: 600, url: imgUrl }); }

        //上传封面
        function upfile_load_click() {
          kaige.upload_multi_files({
            input_id: '#inputimgguid',
            img_id: '#srcimgurl',
            btn: '#editimg',
            url: szoa.client.path + '/pages/files/upfiles.html?id=7'
          });
        }



        //加载列表
        kaige.table({
          elem: '#pageTable',
          title: '仓库管理',
          url: "/crm.supplier/index",
          id: 'pageTable',
          toolbar: '#dtoolbar',
          cols: [[
            { field: 'id', title: 'ID', align: 'center' },
            { field: 'supplier_name', title: '供应商名称', align: 'center' },
            { field: 'supplier_number', title: '供应商编号', align: 'center' },
            { field: 'supplier_address', title: '供应商地址', align: 'center' },
            { field: 'sequence', title: '排序号', align: 'center' },
            { field: 'cellphone', title: '手机号码', align: 'center' },
            { field: 'linkman', title: '联系人', align: 'center' },
            { field: 'status', title: '状态', align: 'center', templet: '#status' },
            { field: 'explain', title: '说明', align: 'center' },
            { title: '操作', toolbar: '#dtrbar', align: 'center', width: 150, fixed: 'right' }
          ]],
          done: function (res, curr, count) {
            //搜索框--回车提交
            $("input[name=keywords]").on('keyup', function (e) {
              if (event.keyCode == 13) {
                $("#btn-search").trigger("click");
              }
            });
            //给筛选表单赋值
            form.val("searchform", {
              "keywords": getkeywords('keywords'),
            });
            form.render(null, 'searchform');
          }
        });

        //触发行双击事件
        table.on('rowDouble(pageTable)', function (obj) {
          barview(obj.data);
          $('.layui-table-click').removeClass('layui-table-click');
          $(obj.tr).addClass('layui-table-click');
        });

        //获取筛选表单
        function getsearchform() {
          var gfv = {
            "keywords": getkeywords('keywords'),
          }
          gfv.rnd = Math.random();
          return gfv;
        }

        //执行重载表格
        function reload_sxtable() {
          var where = getsearchform();
          if (JSON.stringify(where) == "{}") {
            layer.msg('当前没有筛选条件！'); return;
          }
          setTimeout(function () {
            //执行重载
            table.reload('pageTable', {
              height: 'full-30'  //必须写，有时候高度不出来
              , page: { curr: 1 } //置第一页
              , where: where
            });
          }, 300);
        }



        //搜索(筛选)
        function btnsearch() {
          savekeywords('keywords', $("input[name=keywords]").val());
          reload_sxtable();
        }

        //列表-监听表头工具栏事件dtoolbar
        table.on('toolbar(pageTable)', function (obj) {
          var checkStatus = table.checkStatus(obj.config.id);
          switch (obj.event) {
            case 'btn-add':
              /*添加*/
              btnadd();
              break;
            case 'btn-delete':
              /*删除*/
              btndelete(checkStatus);
              break;
            case 'btn-search':
              /*搜索*/
              btnsearch();
              break;
          }
        });

        //列表-监听单元格行工具事件dtrbar
        table.on('tool(pageTable)', function (obj) {
          var that = this;
          var data = obj.data;
          switch (obj.event) {
            case 'edit':
              /*修改*/
              baredit(data);
              break;
            case 'del':
              //删除
              bardel(data);
          }
        });

        function btndelete(d) {
          kaige.del({
            url: "/sys.user/del",
            data: d.data,
            tablelayid: 'pageTable',
          });
        }


        //查看
        function barview(d) {
          kaige.details({
            url: '/crm.supplier/look',
            data: { id: d.id },
            id: 'kaige',
            area: ['750px', '600px'],
            title: '<i class="fa fa-eye"></i> 查看 - 供应商',
            overflow: false,
            callbefore: function (layero, index) {
            },
          });
        }


        //添加
        function btnadd() {
          kaige.form({
            url: "/crm.supplier/add",
            data: {},
            encode: 1,
            id: 'kaige',
            area: ['750px', '600px'],
            title: '<i class="layui-icon layui-icon-add-circle"></i> 添加供应商',
            tablelayid: 'pageTable',
            overflow: false,
            callbefore: function () {
              addeditform();
              upfile_load_click();
              form.verify({
                cellphone: [
                  /^[\S]{11}$/
                  , '手机号码必须11位，且不能出现空格'
                ]
              });
              element.render('collapse');
            }
          });
        }
        //修改
        function baredit(d) {
          kaige.form({
            url: "/crm.supplier/edit",
            data: { id: d.id },
            encode: 1,
            id: 'kaige',
            area: ['750px', '600px'],
            title: '<i class="layui-icon layui-icon-edit"></i>编辑供应商',
            tablelayid: 'pageTable',
            overflow: false,
            callbefore: function () {

              addeditform();
              upfile_load_click();
              element.render('collapse');
            },

          });
        }
        //删除
        function bardel(d) {
          layer.confirm('您确定删除新闻资讯吗？', {
            title: '<i class="layui-icon layui-icon-delete"></i> 删除确认',
            btn: ['确认', '取消']
          }, function () {
            $.post("/crm.supplier/del", { id: d.id }, function (res) {
              res.status && table.reload('pageTable');
              layer.msg(res.msg);
            });
          });
        };
        function addeditform() {
          //仓库保管员
          tableSelect.render({
            elem: '#depot_storeman',
            searchKey: 'keywords',
            checkedKey: 'id',
            table: {
              url: '/select/employee',
              cols: [[
                { type: 'radio' },
                { field: 'name', title: '姓名' },
                { field: 'dept_id_name', title: '部门' },
                { field: 'ranking_id_name', title: '职位' }
              ]],
              where: { automatch: 1 },
            },
            done: function (elem, data) {
              var od = data.data[0];
              elem.val(od.name);
              $('#uid').val(od.id);
            }
          });
          //主持人 
          tableSelect.render({
            elem: '#compere',
            searchKey: 'keywords',
            checkedKey: 'id',
            table: {
              url: '/select/employee',
              cols: [[
                { type: 'radio' },
                { field: 'name', title: '姓名' },
                { field: 'dept_id_name', title: '部门' },
                { field: 'ranking_id_name', title: '职位' }
              ]],
              where: { automatch: 1 },
            },
            done: function (elem, data) {
              var od = data.data[0];
              elem.val(od.name);
              $('#compere_id').val(od.id);
            }
          });
          //状态
          tableSelect.render({
            elem: '#zhuangtai',
            searchKey: 'keywords',
            checkedKey: 'id',
            table: {
              url: '/select/carstatusname',
              cols: [[
                { type: 'radio' },
                { field: 'name', title: '状态' },
              ]],
              where: { automatch: 1 },
            },
            done: function (elem, data) {
              var od = data.data[0];
              elem.val(od.name);
              $('#status_id').val(od.id);
            }
          });

        }

      });
    });
  </script>

  <script type="text/html" id="dtoolbar">
        <div class=" layui-form " lay-filter="searchform">
            
                <div class="layui-inline">
                    <input class="layui-input tsinput" name="keywords" placeholder="供应商名称">
                    <button class="tsbutton" lay-event="btn-search" id="btn-search" title="筛选"><i class="layui-icon layui-icon-search"></i></button>
                </div>
            
            <div class="layui-btn-group" style="margin-top: 2px;">
                <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-add"><i class="layui-icon layui-icon-add-circle"></i> 添加</button>
            </div>
            <span style="margin-left: 20px;color: red;">双击打开详情页</span>
        </div>
  </script>
  <script type="text/html" id="dtrbar">
        <div class="layui-btn-group">
            <button class="layui-btn layui-btn-xs" lay-event="edit" title="编辑"><i class="layui-icon layui-icon-edit"></i></button>
            <button class="layui-btn layui-btn-xs" lay-event="del" title="删除"><i class="layui-icon layui-icon-delete"></i></button>
        </div>
  </script>
  <script type="text/html" id="status">
    <span class="layui-badge {{ d.status == 1? 'layui-bg-blue': 'layui-bg-gray'}}">{{ d.status == 1? '是':'否' }}</span>
  </script>
  <script type="text/html" id="kaige_form_html">
        <form class="layui-form layui-form-pane kaige-body-form" lay-filter="kaige_form_lay_filter" style="padding: 5px;">
          {{# if(d.id){ }}
          <input type="hidden" name="id" value="{{ d.id }}" />
          {{# } }}

          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">供应商名称</label>
              <div class="layui-input-inline">
                <input type="text" name="supplier_name" value="{{d.supplier_name||''}}" lay-verify="required|supplier_name" 
                  autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">供应商编号</label>
              <div class="layui-input-inline">
                <input type="text" name="supplier_number" value="{{d.supplier_number||''}}" 
                  autocomplete="off" class="layui-input">
              </div>
            </div>
          </div>   
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">供应商地址</label>
            <div class="layui-input-inline">
              <input type="text" name="supplier_address" value="{{d.supplier_address||''}}" 
                autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-inline">
              <input type="text" name="sequence" value="{{d.sequence||''}}" 
                autocomplete="off" class="layui-input" lay-verify="required|sequence">
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">联系人</label>
            <div class="layui-input-inline">
              <input type="text" name="linkman" value="{{d.linkman||''}}" 
                autocomplete="off" class="layui-input" lay-verify="required|linkman">
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">手机号码</label>
            <div class="layui-input-inline">
              <input type="text" name="cellphone" value="{{d.cellphone||''}}" 
                autocomplete="off" class="layui-input" lay-verify="required|cellphone">
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">是否启用</label>
          <div class="layui-input-inline">
            <input type="checkbox" name="status" lay-skin="switch" lay-text="是|否" {{# if (d.status==1){ }}checked="" {{# } }} />
          </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">供应商邮箱</label>
            <div class="layui-input-inline">
              <input type="text" name="mailbox" value="{{d.mailbox||''}}" 
                autocomplete="off" class="layui-input" lay-verify="required|mailbox">
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">说明</label>
          <div class="layui-input-block">
            <textarea name="explain" class="layui-textarea" style="width:81%;">{{ d.explain || '' }}</textarea>
          </div>
        </div>
        <div class="layui-form-item layui-hide">
        <button class="layui-hide" lay-submit="" id="kaige_form_btn_save" lay-filter="kaige_form_btn_save">保存数据</button>
      </div>
        </form>
  </script>



</body>

</html>